#include <rtthread.h>
#include "base.h" 
#include "rtconfig.h"

static struct rt_semaphore sem1;
static struct rt_semaphore sem2;

void task1_entry (void * param) {
    int i = 1;
    
    while (1) {
        rt_sem_take(&sem1, RT_WAITING_FOREVER);
        
        rt_kprintf("Task1: %d\n", i);
        i += 2;
        rt_thread_mdelay(100);
        
        rt_sem_release(&sem2);
    }
}

void task2_entry (void * param) {
    int i = 2;
    
    while (1) {
        rt_sem_take(&sem2, RT_WAITING_FOREVER);
        
        rt_kprintf("Task2: %d\n", i);
        i += 2;
        rt_thread_mdelay(100);
        
        rt_sem_release(&sem1);
    }
}


int main (void) {
    hardware_init();
      
    rt_sem_init(&sem1, "sem1", 1, RT_IPC_FLAG_FIFO);
    rt_sem_init(&sem2, "sem2", 0, RT_IPC_FLAG_FIFO);
    
    rt_thread_t t2 = rt_thread_create("t2", task2_entry, RT_NULL, 4096, 0, 10);
    rt_thread_startup(t2);
    rt_thread_t t1 = rt_thread_create("t1", task1_entry, RT_NULL, 4096, 0, 10);
    rt_thread_startup(t1);   
}
